package uiLayer;

import modelLayer.ClassRoom;
import modelLayer.Teacher;
import modelLayer.TeachingBlock;
import uiLayer.util.AbstractEditableCustomTable;

public class TeachingBlockTable extends AbstractEditableCustomTable<TeachingBlock> {

	public TeachingBlockTable(){
		super();
		super.setColNames("Fag", "Lærer", "Lokale");
		//Property on JTable which stops editing and saves changes when focus lost from the table:
		putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
	}
	@Override
	public boolean doIsCellEditable(int rowIndex, int columnIndex) {
		return columnIndex == 2;
	}

	@Override
	public void doSetValueAt(Object aValue, int columnIndex, TeachingBlock tb) {
		switch (columnIndex) {
		//remove the comment below in order to make the comboBox in the teacher column activated and editable
//		case 1:
//			tb.getSubject().setTeacher((Teacher)aValue);
//			break;
		case 2:
			tb.setClassRoom((ClassRoom)aValue);
			break;
		}
	}

	@Override
	public Object getCellValue(int col, TeachingBlock o) {
		Object res = null;
		switch (col) {
		case 0:
			res = o.getName();
			break;
		case 1:
			res = o.getTeacher();
			break;
		case 2:
			res = o.getClassRoom();
			break;
		}
		return res;
	}

}
